package com.kitty.game.task.service.taskHandler;

import com.kitty.game.role.model.Role;
import com.kitty.game.config.TaskSet;
import com.kitty.game.task.TaskDataPool;
import com.kitty.game.task.message.vo.TaskInfo;
import com.kitty.game.task.model.product.TaskType;
import org.springframework.stereotype.Component;

import java.text.MessageFormat;

@Component
public class GodProtectTaskHandler extends TaskHandler {
    @Override
    public TaskType getTaskType() {
        return TaskType.GOD_PROTECT;
    }

    @Override
    public TaskInfo getTaskInfo(Role role, TaskSet taskSet) {
        TaskInfo taskInfo = super.getTaskInfo(role, taskSet);
        taskInfo.setTaskZhiyin(MessageFormat.format(taskSet.getTaskZhiyin(), role.getNoDeath()));
        taskInfo.setTaskJiangli(MessageFormat.format(taskSet.getTaskGift(), role.getNoDeath()));
        return taskInfo;
    }

    public boolean acceptTask(Role role) {
        TaskSet taskSet = taskService.getTaskSet(TaskDataPool.GOD_PROTECT_TASKID, role);
        /**任务已经接取时，只更新次数*/
        if (taskService.isTaskAccepted(role, taskSet)) {
            pushTask(role, taskSet);
            return true;
        } else {
            return acceptTask(role, taskSet);
        }
    }

    public boolean resetTask(Role role) {
        TaskSet taskSet = taskService.getTaskSet(TaskDataPool.GOD_PROTECT_TASKID, role);
        doResetTask(role, taskSet);
        doAfterReset(role, taskSet);
        return true;
    }

    public void pushTask(Role role) {
        TaskSet taskSet = taskService.getTaskSet(TaskDataPool.GOD_PROTECT_TASKID, role);
        pushTask(role, taskSet);
    }
}
